/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Text;
using System.Linq;
using System;
#if _LOCALDB
  using Oceanside.LocalDB;
#else
using Oceanside.RemoteDB;
#endif

namespace Oceanside
{
    public class Init
    {
        public static void Assign()
        {
            //////////////////////////////////////////////////////////////////////////
            ///For the reports window. 0-12
            //////////////////////////////////////////////////////////////////////////
            ///Top
            PosWindow.ReportListBoundFunctions.Add(new Oceanside.Desktop("Back"));


            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.SalesByRevenueCenterReport("Sales by Revenue Center"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.SalesByRevenueTypeReport("Sales by Revenue Type"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.SalesByDaypartReport("Sales by Daypart"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.SalesByProductGroup("Sales by Product Group"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.SalesByEmployeeReport("Sales by Employee"));

            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.QuickReports("Print One-Click Sales Reports"));
            

            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DiscountsByEmployeeReport("Promos by Employee"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DiscountsByManagerReport("Promos by Manager"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DiscountsByTypeReport("Promos by Type"));

            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());

            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.VoidsByEmployeeReport("Voids by Employee"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.VoidsByManagerReport("Voids by Manager"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.VoidsByTypeReport("Voids by Type"));

            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.CompsByEmployeeReport("Comps by Employee"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.CompsByManagerReport("Comps by Manager"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.CompsByTypeReport("Comps by Type"));

            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.EmployeeReport("Employees"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.CheckoutReport("Checkout History"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.PayrollReport("Payroll Report"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.FixTimePunches("Adjust Time Punches"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());

            /////These Buttons are actually towards the top of the page because of their tag number.
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());            
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.MasterSalesReport("Master Sales Report"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.SalesByDayOfWeek("Sales by Day of Week"));
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());
            //PosWindow.ReportListBoundFunctions.Add(new Oceanside.DoNothing());

            //////////////////////////////////////////////////////////////////////////
            ///For the order history window. 0-11
            //////////////////////////////////////////////////////////////////////////
            ///Top
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.ViewOrder("View"));
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.ReopenOrder("Reopen"));
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CheckHistoryBoundFunctions.Add(new Oceanside.DoNothing());

            //////////////////////////////////////////////////////////////////////////
            ///For the time sheet window. 0-11
            //////////////////////////////////////////////////////////////////////////
            ///Top
            PosWindow.TsListBoundFunctions.Add(new Oceanside.PayIn("Pay Cash In"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.PayOut("Pay Cash Out"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.SetUserPassword("Set Magnetic Password"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.ClaimDrawer2("Claim Drawer Two Lock"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.ReleaseDrawer2("Release Drawer Two Lock"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.PopDrawer2("Open Drawer Two"));

            ///Bottom
            PosWindow.TsListBoundFunctions.Add(new StartBusinessDayCash("Business Day Cash Start"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.DepositMoney("Cash Drop"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.PrintLastCheckout("Print Last Checkout"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.ClaimDrawer("Claim Drawer One Lock"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.ReleaseDrawer("Release Drawer One Lock"));
            PosWindow.TsListBoundFunctions.Add(new Oceanside.PopDrawer("Open Drawer One"));

            //////////////////////////////////////////////////////////////////////////
            ///For the close check window 0-25
            //////////////////////////////////////////////////////////////////////////
            ///Top
            PosWindow.CCListBoundFunctions.Add(new Oceanside.Desktop("Desktop"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.PopOwnersDrawer("Open Drawer"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.ShowFinancialWindow("Finance"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.SwitchToOrderScreen("Order Screen"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.PrintChecksRemainingBalance("Print Balance"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.PrintCashReceipt("Cash Receipt"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.PrintItemizedReceipt("Itemized Receipt"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.PrintCreditCardReceipt("Card Receipt"));


            ///Bottom
            PosWindow.CCListBoundFunctions.Add(new Oceanside.ScrollCheckDown());
            if (!Constants.IsQuickServiceMode)
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.SplitCheck("Split Check"));
            }
            else
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.DoNothing());
            }

            PosWindow.CCListBoundFunctions.Add(new Oceanside.ScrollCheckUp());

            if (!Constants.IsQuickServiceMode)
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.VoiceAuthCommand("Voice Auth"));
                PosWindow.CCListBoundFunctions.Add(new Oceanside.PayWithCardOnCheck("Card on Check"));
            }
            else
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.PreviousOrder("Previous Order"));
                PosWindow.CCListBoundFunctions.Add(new Oceanside.NextOrder("Next Order"));
            }
            PosWindow.CCListBoundFunctions.Add(new Oceanside.SplitBySeat("Checks by Seat"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.Discount("Discount"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.CompItem("Comp Item(s)"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.VoidItem("Void Item(s)"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.HouseAccountPayment("House Payment"));

            ///Misc
            PosWindow.CCListBoundFunctions.Add(new Oceanside.HandleVoidSale("Void Payment"));
            PosWindow.CCListBoundFunctions.Add(new Oceanside.AdjustGratuity("Adjust Gratuity"));

            if (!Constants.IsQuickServiceMode)
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.CloseTable("Close Table"));
            }
            else
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.CloseTable("Close Order"));
            }
            PosWindow.CCListBoundFunctions.Add(new Oceanside.ScrollPaymentLeft());
            PosWindow.CCListBoundFunctions.Add(new Oceanside.ScrollPaymentRight());
            PosWindow.CCListBoundFunctions.Add(new Oceanside.CheckPayment("Pay by Check"));

            if (!Constants.IsQuickServiceMode)
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.ReprintEqualPay("Reprint Equal"));
                PosWindow.CCListBoundFunctions.Add(new Oceanside.EqualPay("Equal Receipts"));
            }
            else
            {
                PosWindow.CCListBoundFunctions.Add(new Oceanside.DoNothing());
                PosWindow.CCListBoundFunctions.Add(new Oceanside.DoNothing());
            }

            //////////////////////////////////////////////////////////////////////////
            ///For the control panel window 0-14
            //////////////////////////////////////////////////////////////////////////
            ///Misc
            PosWindow.CpListBoundFunctions.Add(new Oceanside.ExitCp("Lock"));
            PosWindow.CpListBoundFunctions.Add(new Oceanside.ScrollTablesUP());
            PosWindow.CpListBoundFunctions.Add(new Oceanside.ScrollTablesDown());
            PosWindow.CpListBoundFunctions.Add(new Oceanside.CheckHistory("Order History"));
            PosWindow.CpListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CpListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CpListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.CpListBoundFunctions.Add(new Oceanside.DoNothing());

            if (!Constants.IsQuickServiceMode)
            {
                PosWindow.CpListBoundFunctions.Add(new Oceanside.CombTables("Merge Two Tables"));
            }
            else
            {
                PosWindow.CpListBoundFunctions.Add(new Oceanside.DoNothing());
            }

            //Bottom
            if (Constants.IsQuickServiceMode)
            {
                PosWindow.CpListBoundFunctions.Add(new Oceanside.NewOrder("New Order"));
            }
            else
            {
                PosWindow.CpListBoundFunctions.Add(new Oceanside.NewTableCp("New Table"));
            }

            PosWindow.CpListBoundFunctions.Add(new Oceanside.TimeSheet("Time Clock"));
            PosWindow.CpListBoundFunctions.Add(new Oceanside.ShowFinancialWindow("Finance"));
            PosWindow.CpListBoundFunctions.Add(new Oceanside.SystemConfig("System"));
            PosWindow.CpListBoundFunctions.Add(new Oceanside.Reports("Reports"));


            if (!Constants.IsQuickServiceMode)
            {
                PosWindow.CpListBoundFunctions.Add(new Oceanside.XferTable("Transfer Table"));
            }
            else
            {
                PosWindow.CpListBoundFunctions.Add(new Oceanside.DoNothing());
            }

            //////////////////////////////////////////////////////////////////////////
            ///For the place order window 0-24, For Quick Serve Order 0-54
            //////////////////////////////////////////////////////////////////////////
            if (Constants.IsQuickServiceMode)
            {
                ///Top
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Desktop("Desktop"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ClearSeat("Clear Seat"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ReprintReceipts("Reprint Receipts"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Done("Lock"));

                PosWindow.PoListBoundFunctions.Add(new Oceanside.MakePayment("Payment Screen"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.QuickCashPayment());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.QuickCheckPayment());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.QuickCreditPayment());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.QuickDiscount());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.GiftCardBalance("Giftcard Balance"));


                ///Bottom
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ScrollTicketDown());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.NewOrderQS("New Order"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ScrollTicketUp());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DoNothing());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.PopOwnersDrawer("Open Drawer"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.CloneProduct("Repeat"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.RepeatQuantity("Repeat Quantity"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.NoTax("Clear Tax"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Delete("Delete Item"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DeleteTable("Delete Order"));

                ///Aux
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DoNothing());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DoNothing());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DoNothing());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DoNothing());
                //PosWindow.PoListBoundFunctions.Add(new Oceanside.AnswerCallerId("Answer Call"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.BarSeatOrExitMod());

                ///All of the spare POS Buttons used in quick-service.
                LoadDynamicOrderButtons();
            }
            else
            {
                ///Top
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Desktop("Desktop"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ClearSeat("Clear Seat"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.SeeServer("See Server"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.SplitSeat("Split Seat"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Done("Lock"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.SubmitOrder("Send Order"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.PrintBarSlip("Print Subtotal"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.NewTablePo("New Table"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.BarSeatOrExitMod("Bar Seat"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.CustomerName("Table Name"));

                ///Bottom
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ScrollTicketDown());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.NewSeat("New Seat"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ScrollTicketUp());
                PosWindow.PoListBoundFunctions.Add(new Oceanside.MakePayment("Payment Screen"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.PopOwnersDrawer("Open Drawer"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.CloneProduct("Repeat"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.RepeatQuantity("Repeat Quantity"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.ExceptionModify("Excpn. Modify"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Delete("Delete Item"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DeleteTable("Delete Order"));

                ///Aux
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Delivery("Delivery"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.TakeOut("Takeout"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.AsAppetizer("As Appet."));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.DontMake("Don't Make"));
                PosWindow.PoListBoundFunctions.Add(new Oceanside.Hold("Hold"));
            }

            ////////////////////////////////////////////////////////////////////////////
            /////For the financial window 0-11
            ////////////////////////////////////////////////////////////////////////////
            PosWindow.FinListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.FinListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.FinListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.FinListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.FinListBoundFunctions.Add(new Oceanside.DoNothing());
            PosWindow.FinListBoundFunctions.Add(new Oceanside.DoNothing());

            PosWindow.FinListBoundFunctions.Add(new Oceanside.CreditCardTips("Credit Tip Total"));
            PosWindow.FinListBoundFunctions.Add(new Oceanside.SearchTransaction("Find Transaction"));
            PosWindow.FinListBoundFunctions.Add(new Oceanside.CloseoutHouse("Closeout House"));
            PosWindow.FinListBoundFunctions.Add(new Oceanside.PreliminaryCloseout("Preliminary Closeout"));
            PosWindow.FinListBoundFunctions.Add(new Oceanside.ViewTransactionsOrder("View Related Order"));
            PosWindow.FinListBoundFunctions.Add(new Oceanside.DoNothing());

            ////////////////////////////////////////////////////////////////////////////
            /////For the split seat and/or split check window 0-1
            ////////////////////////////////////////////////////////////////////////////
            PosWindow.SplitBoundFunctions.Add(new Oceanside.MoveItemLeft());
            PosWindow.SplitBoundFunctions.Add(new Oceanside.MoveItemRight());
            PosWindow.SplitBoundFunctions.Add(new Oceanside.SplitTicketDown());
            PosWindow.SplitBoundFunctions.Add(new Oceanside.SplitTicketUp());
            PosWindow.SplitBoundFunctions.Add(new Oceanside.SplitTicketDown2());
            PosWindow.SplitBoundFunctions.Add(new Oceanside.SplitTicketUp2());


            ////////////////////////////////////////////////////////////////////////////
            /////For the transfer check window 0
            ////////////////////////////////////////////////////////////////////////////
            PosWindow.TransferTableBoundFunctions.Add(new Oceanside.TransferTableRight());
            PosWindow.TransferTableBoundFunctions.Add(new Oceanside.ScrollTablesDownXfer());
            PosWindow.TransferTableBoundFunctions.Add(new Oceanside.ScrollTablesUPXfer());
            PosWindow.TransferTableBoundFunctions.Add(new Oceanside.ScrollTablesDownXfer2());
            PosWindow.TransferTableBoundFunctions.Add(new Oceanside.ScrollTablesUPXfer2());

            ////////////////////////////////////////////////////////////////////////////
            /////For the combine checks window
            ////////////////////////////////////////////////////////////////////////////
            PosWindow.CombineTableBoundFunctions.Add(new Oceanside.TransferTableRightComb("Merge"));
            PosWindow.CombineTableBoundFunctions.Add(new Oceanside.ScrollTablesDownComb());
            PosWindow.CombineTableBoundFunctions.Add(new Oceanside.ScrollTablesUPComb());
            PosWindow.CombineTableBoundFunctions.Add(new Oceanside.ScrollTablesDownComb2());
            PosWindow.CombineTableBoundFunctions.Add(new Oceanside.ScrollTablesUPComb2());
        }

        public static void LoadDynamicOrderButtons()
        {
            try
            {
                using (DominicaEntities context = new DominicaEntities(DominicaEntities.GetEfConString()))
                {
                    foreach (WrapPanel wp in QuickOrderWindow.WrapPanels)
                    {
                        foreach (UIElement el in wp.Children)
                        {
                            if (el is Button_95_50)
                            {
                                Button_95_50 b = (el as Button_95_50);
                                if (SetButtonStyle(b, context))
                                {
                                    b.ButtonDownDelegate += new Button_95_50.FunctionButtonDownDelegate(b.OrderProduct);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
            }
        }

        private static bool SetButtonStyle(Button_95_50 b, DominicaEntities context)
        {
            bool hasStyle = false;
            if (b != null)
            {
                try
                {
                    string tag = b.Tag as string;
                    LAYOUTOBJ lo = context.LAYOUTOBJS.
                            Where(o => o.PagedId == PAGELAYOUT.CONST_PAGE_TYPE_ORDERSCREEN
                                && o.Tag != null && o.Tag.Equals(tag)).FirstOrDefault();

                    if (lo != null && !string.IsNullOrEmpty(lo.Style))
                    {
                        b.SetResourceReference(Button_95_50.StyleProperty, lo.Style);
                        b.ProductId = (Int64)lo.ProductId;
                        b.ProductGroupId = (Int64)lo.CategoryId;
                        b.ButtonLabelText = lo.ButtonText;
                        b.Visibility = Visibility.Visible;
                        hasStyle = true;
                    }
                    else
                    {
                        b.Visibility = Visibility.Hidden;
                    }
                }
                catch (Exception ex)
                {
                    b.Visibility = Visibility.Hidden;
                    Logging.LogException(ex);
                }
            }
            return hasStyle;
        }
    }
}
